//
//  HMMessageTableViewController.swift
//  WeiBo14
//
//  Created by HM on 16/3/2.
//  Copyright © 2016年 HM. All rights reserved.
//

import UIKit

class HMMessageTableViewController: HMVisitorViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 如果没有登录,去设置没有登录的访客视图信息
        if !userLogon {
            // 拿到访客视图View,去设置信息
            visitorView.setPageInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            return
        }
        
        
        let button = UIButton()
        button.setTitle("哈哈", forState: UIControlState.Normal)
        button.backgroundColor = UIColor.redColor()
        button.sizeToFit()

        navigationItem.titleView = button
        
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "发现群", target: self, action: "findGroup")
        
        
        tabBarItem.badgeValue = "10"
        for tabBarSubView in (tabBarController?.tabBar.subviews)! {
            // 判断是否是 UITabBarButton
            if tabBarSubView.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                for tabBarButtonSubView in tabBarSubView.subviews {
                    // 判断是否是 _UIBadgeView
                    if tabBarButtonSubView.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                        for badgeSubView in tabBarButtonSubView.subviews {
                            if badgeSubView.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                print("终于找到你,还好没放弃")
                                
                                badgeSubView.setValue(UIImage(named: "main_badge"), forKey: "_image")
//                                // UnsafeMutablePointer
//                                var i: UInt32 = 0
//                                
//                                // 如何去获取一个未知类身上的属性
//                                let ivars = class_copyIvarList(NSClassFromString("_UIBadgeBackground")!, &i)
//                                for i in 0..<i {
//                                    let ivar = ivars[Int(i)]
//                                    let name = ivar_getName(ivar)
//                                    let nameStr = String(CString: name, encoding: NSUTF8StringEncoding)
//                                    
//                                    let type = ivar_getTypeEncoding(ivar)
//                                    let typeStr = String(CString: type, encoding: NSUTF8StringEncoding)
//                                    print("name=\(nameStr),type=\(typeStr)")
//                                }
                            }
                        }
                    }
                }
            }
        }
        
        tabBarItem.badgeValue = nil
        tabBarItem.badgeValue = "20"
        
        
    }

    
    func findGroup(){
        print("发现群")
        let vc = HMTemp2ViewController()
        navigationController?.pushViewController(vc, animated: true)
    }

}

/**
(

"<SnapKit.LayoutConstraint:0x7fb65a4a1950@/Users/xiele/Desktop/iPhone\U9879\U76ee/05-iPhone\U9879\U76ee-\U7b2c6\U5929(\U9996\U9875Cell\U5e03\U5c40)/04-\U6e90\U4ee3\U7801/10-\U8f6c\U53d1\U5fae\U535a\U663e\U793a/WeiBo14/WeiBo14/Classes/View/Home/View/HMStatusCell.swift#81 WeiBo14.HMRetweetStatusView:0x7fb65ad1c040.top == WeiBo14.HMOriginalStatusView:0x7fb65ad15d60.bottom>", --> 没问题
"<SnapKit.LayoutConstraint:0x7fb65a4a7b50@/Users/xiele/Desktop/iPhone\U9879\U76ee/05-iPhone\U9879\U76ee-\U7b2c6\U5929(\U9996\U9875Cell\U5e03\U5c40)/04-\U6e90\U4ee3\U7801/10-\U8f6c\U53d1\U5fae\U535a\U663e\U793a/WeiBo14/WeiBo14/Classes/View/Home/View/HMStatusCell.swift#86 WeiBo14.HMStatusToolBar:0x7fb65ad17280.top == WeiBo14.HMRetweetStatusView:0x7fb65ad1c040.bottom>", --> 没问题
"<SnapKit.LayoutConstraint:0x7fb65ad106d0@/Users/xiele/Desktop/iPhone\U9879\U76ee/05-iPhone\U9879\U76ee-\U7b2c6\U5929(\U9996\U9875Cell\U5e03\U5c40)/04-\U6e90\U4ee3\U7801/10-\U8f6c\U53d1\U5fae\U535a\U663e\U793a/WeiBo14/WeiBo14/Classes/View/Home/View/HMStatusCell.swift#44 WeiBo14.HMStatusToolBar:0x7fb65ad17280.top == WeiBo14.HMOriginalStatusView:0x7fb65ad15d60.bottom>" --> 与上面一个约束冲突
)

Will attempt to recover by breaking constraint
<SnapKit.LayoutConstraint:0x7fb65a4cffd0@/Users/xiele/Desktop/iPhone项目/05-iPhone项目-第6天(首页Cell布局)/04-源代码/10-转发微博显示/WeiBo14/WeiBo14/Classes/View/Home/View/HMRetweetStatusView.swift#35 WeiBo14.HMRetweetStatusView:0x7fb65ad1c040.bottom == UILabel:0x7fb65a4d7d20.bottom + 8.0>




*/